package com.library.controller;


import com.library.domain.Publisher;
import com.library.mapper.PublisherMapper;
import com.library.service.PublisherService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/lib/pub")
public class PublisherController{
    @Autowired
    PublisherService publisherService;
    @Autowired
    PublisherMapper publisherMapper;

    private String prefix = "system/library/pub";

    @GetMapping("/selectAll")
    public List<Publisher> selectAll() {

        return publisherService.selectAll();
    }

    @GetMapping("/key/{key}")
    public List<Publisher> selectKey(@PathVariable String key){
        return publisherMapper.selectKey(key);

    }
    @GetMapping("/pubs")
    public List<String> selectAus(){
        return publisherMapper.selectPubs();
    }
    @GetMapping()
    public String pub(){
        return prefix+"/pub";
    }

    @PostMapping("/add")
    public Integer add(@RequestBody Publisher publisher) {
        return publisherService.add(publisher);
    }

    @DeleteMapping("/del/{pid}")
    public Integer del(@PathVariable int pid) {
        return publisherService.del(pid);
    }

    @CrossOrigin
    @PostMapping("/change")
    public Integer change(@RequestBody Publisher publisher) {
        return publisherService.change(publisher);
    }
}
